package com.demo.io.talk1;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @author : YU.TAN
 * @date : 2021/11/15 15:34
 */
public class UdpClientDemo1 {
    public static void main(String[] args) throws Exception {
        //1.建立一个Socket
        DatagramSocket socket=new DatagramSocket();
        //2.建个包
        String msg="Hello,World!";
        //3.发送给谁
        InetAddress address = InetAddress.getByName("localhost");
        int port = 9090;

        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, address, port);
        //4.发送包
        socket.send(packet);

        socket.close();



    }
}
